package com.cxm.support.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cxm.support.entity.Chart;
import com.cxm.support.entity.User;
import com.cxm.support.mapper.ChartMapper;
import com.cxm.support.service.ChartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxm.support.vo.DataVO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cxm
 * @since 2022-05-13
 */
@Service
public class ChartServiceImpl extends ServiceImpl<ChartMapper, Chart> implements ChartService {
    @Autowired
    private ChartMapper chartMapper;

    @Override
    public DataVO findData(Integer page, Integer limit) {
        Subject subject= SecurityUtils.getSubject();
        User user = (User) subject.getSession().getAttribute("user");
        String username = user.getUsername();
        DataVO dataVO = new DataVO();
        dataVO.setCode(0);
        dataVO.setMsg("");
        Page<Chart> page2 = new Page<>(page, limit);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.orderByDesc("id");
        wrapper.eq("author",username);
        Page<Chart> page3 = chartMapper.selectPage(page2, wrapper);
        dataVO.setCount(page3.getTotal());
        List<Chart> TypecontentList = page3.getRecords();
        dataVO.setData(TypecontentList);
        return dataVO;
    }

    @Override
    public DataVO findWaitData(Integer page, Integer limit) {
        DataVO dataVO = new DataVO();
        dataVO.setCode(0);
        dataVO.setMsg("");
        Page<Chart> page2 = new Page<>(page, limit);
        QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("status","待审核");
        wrapper.orderByDesc("id");
        Page<Chart> page3 = chartMapper.selectPage(page2, wrapper);
        dataVO.setCount(page3.getTotal());
        List<Chart> TypecontentList = page3.getRecords();
        dataVO.setData(TypecontentList);
        return dataVO;

    }

    @Override
    public DataVO findWorkData(Integer page, Integer limit) {
        DataVO dataVO = new DataVO();
        dataVO.setCode(0);
        dataVO.setMsg("");
        Page<Chart> page2 = new Page<>(page, limit);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("status","处理中");
        wrapper.orderByDesc("id");
        Page<Chart> page3 = chartMapper.selectPage(page2, wrapper);
        dataVO.setCount(page3.getTotal());
        List<Chart> TypecontentList = page3.getRecords();
        dataVO.setData(TypecontentList);
        return dataVO;
    }
}
